<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
    <title>微信菜单</title>
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
	<link href="https://cdn.staticfile.org/font-awesome/5.11.2/css/all.min.css" rel="stylesheet">
	<link href="/static/basic/plugins/SmartWizard-4.2.2/css/smart_wizard.css" rel="stylesheet" type="text/css">
	<link href="/static/basic/plugins/SmartWizard-4.2.2/css/smart_wizard_theme_arrows.min.css" rel="stylesheet" type="text/css">
	<link rel="stylesheet" type="text/css" href="/static/basic/plugins/webuploader/webuploader.css?v=12171">
	<link rel="stylesheet" type="text/css" href="/view/gas/station/style.css?v=1">
	<link rel="stylesheet" type="text/css" href="/static/m.css?v=1227" >
	<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
<script src="/static/init.js"></script>
<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>	
<script src="/static/searchEdit.js?v=dd"></script>
    
	
</head>
<body>
<div class="easyui-layout" data-options="fit:true"  >
	<div data-options="region:'west'" style="width:400px;">
		<div class="easyui-layout" data-options="fit:true"  >
			<div data-options="region:'center'" >
				<table id="gridList" ></table>
			</div>
			<div data-options="region:'north'">
					<a href="javascript:void(0)" id="addButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
					<a href="javascript:void(0)" id="editButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">编辑</a>
					<a href="javascript:void(0)" id="removeButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
					<a href="javascript:void(0)" id="saveButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'">保存</a>
					<!-- <a href="javascript:void(0)" id="setDefaultMenuButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">设置默认菜单</a> -->
					<a href="javascript:void(0)" id="takeEffectButton" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">默认菜单立即生效</a>
			</div>
		</div>
	</div>
	<div data-options="region:'center'" style="line-height: 0;">
		<iframe id="itemFrame" scrolling="no" frameborder="0" style="width:100%;height:100%;" src="" url="/view/sys/wx_menu_item/list.html"></iframe>
	</div>
	
</div>
<div id="searchbar" style="padding:2px 5px;">
<form id="searchForm" >
	<!-- 公众号:<input id="search-wx_account_id" name="wx_account_id" /> -->
	<!-- 状态:<input id="search-status" name="status" /> -->
	<a id="searchButton" href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" >查询</a>
</form>
</div>
<script>
var options={
		onClickRow:linkItem,
		page_id:79,
		grid_id:"gridList",
		sqlname:"grid_79_wx_menu"
	};
	//document ready
	$(function(){
		grid1=new uniontrip.datagrid.searchEdit(options);
		
		$('#searchButton').bind('click',grid1.load);//查询操作绑定事件
		$('#addButton').bind('click', addRow);//新增行绑定事件
		$('#editButton').bind('click',grid1.editRow);//编辑按钮绑定事件
		$('#removeButton').bind('click',grid1.remove);//删除行绑定事件
		$('#saveButton').bind('click', grid1.accept);//保存datagrid绑定事件
		$('#cancelEditButton').bind('click',grid1.cancelEditing);//取消行编辑绑定事件
		$('#endEditingButton').bind('click', grid1.endEditing);//结束行编辑绑定事件
		$('#rejectButton').bind('click', grid1.rejectChanges);//撤销编辑绑定事件		
	    $('#showChangesButton').bind('click',grid1.showChanges);//信息变更提示
	    //$('#setDefaultMenuButton').bind('click', setDefaultMenuButton);//
	    $('#takeEffectButton').bind('click', takeEffect);//立即生效默认菜单
	    //初始化搜索框
	    initsearch();
	});
	/**
	 * 单击行事件
	 * @returns
	 */
	function linkItem(index,row){
		var url=$("#itemFrame").attr("url");
		$("#itemFrame").attr("src",url+"?wx_menu_id="+row.id)
	}
	/**
	 * 新增一行
	 */
	function addRow(){
		var newRowData={id:guid(),creator_id:sessionuser.id,creator_name:sessionuser.nickname};//初始化行数据
		grid1.grid.datagrid('append',newRowData);	
	}
	/**
	 * 初始化搜索条件
	 */
	function initsearch(){

		
		$('#search-status').combobox({
	    	panelHeight:'auto',
			editable:false,
	    	valueField:'code_value',
			textField:'code_name',
			icons: [{
				iconCls:'icon-clear',
				handler:function(){
					$('#search-status').combobox('clear');
				}
			}],
	        data:grid1.comboboxDatas.status
	    });
		/*$('#search-wx_account_id').combobox({
	    	panelHeight:'auto',
			editable:false,
	    	valueField:'code_value',
			textField:'code_name',
			icons: [{
				iconCls:'icon-clear',
				handler:function(){
					$('#search-wx_account_id').combobox('clear');
				}
			}],
	        data:grid1.comboboxDatas.wx_account_id
	    });*/
	}
	/**
	 * 设置默认菜单
	 */
	function setDefaultMenuButton(){
		var selectRows=grid1.grid.datagrid('getSelections');
		if(selectRows.length>0){
			selectRowid=selectRows[0].id;
			var wx_account_id=selectRows[0].wx_account_id;
			$.ajax({
	    		type: "post",
	    		url: "/authenticated/ajax/updates/update_set_default_wx_menu",
	    		data:JSON.stringify({id:selectRowid,wx_account_id:wx_account_id}),
	    		dataType:"json",
	    		success: function(result){
	    			if(result.success){
	    				$.messager.alert("提示", "设置成功！");
	    				grid1.grid.datagrid("load");
	    			}else{
	    				$.messager.alert("提示", "设置失败！<br>"+result.message);
	    			}
	    		}
	    	});
		}else{
			$.messager.alert("提示", "请选择一条数据！");
		}
	}
	/**
	 * 默认菜单立即生效
	 */
	function takeEffect(){
		var selectRows=grid1.grid.datagrid('getSelections');
		if (grid1.grid.datagrid('endEditing')){
			var changesRows=grid1.grid.datagrid('getChanges');
			if(changesRows.length>0){
				$.messager.alert("提示", "请先保存修改！");
				return;
			}
		}else{
			$.messager.alert("提示", "请先保存修改！");
			return;
		}
		if(selectRows.length>0){
			selectRowid=selectRows[0].id;
			var default_menu=selectRows[0].default_menu;
			if(default_menu=="default"){
				var wx_account_id=selectRows[0].wx_account_id;
				$.post("/authenticated/wxmenu/takeEffectDefault",JSON.stringify({id:selectRowid,appid:selectRows[0].appid}),function(result){
					if(result.success){
						$.messager.alert("提示", "生效成功！");
					}else{
						$.messager.alert("提示", "生效失败！<br>"+result.message);
					}
				});
			}else{
				$.messager.alert("提示", "请选择一条默认菜单！");
			}
		}else{
			$.messager.alert("提示", "请选择一条数据！");
		}
	}
</script>
</body>
</html>